<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>你好呀</title>
  </head>

  <body>
    <button onclick="clearIntervalTitle()">关闭</button>
    <script>
      let IntervalId = setInterval('titleScroll()', 2000);
      function titleScroll() {
        let title = document.title;
        let firstr = title.charAt(0);
        let leftstr = title.substring(1, title.length);
        console.log(leftstr + firstr, leftstr, firstr);
        document.title = leftstr + firstr;
      }
      function clearIntervalTitle() {
        // 清除计数器，关掉标题跑马灯，需要时调用
        clearInterval(IntervalId);
        console.log('关闭');
      }
    </script>
  </body>
</html>
